package com.yr.ryjk.param.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yr.ryjk.common.ErrorType;
import com.yr.ryjk.common.Pagination;
import com.yr.ryjk.param.dao.ParamMapper;
import com.yr.ryjk.param.entity.Key;
import com.yr.ryjk.param.entity.Param;
import com.yr.ryjk.util.JSONUtil;

@Service
public class ParamService implements IParamService{
	@Autowired
	private  ParamMapper paramMapper;
	
	@Override
	public Param getParamByKeyword(String keyword) {
		return  paramMapper.selectByPrimaryKey(keyword);
	}
	
	@Override
	public Map<String, Object> getListOfPage(int pageNo, int pageSize,String des,String keyword) {
		List<Param> list=paramMapper.selectOfPage((pageNo-1)*pageSize,pageSize,des,keyword);
		int count=paramMapper.selectCount(des,keyword);
		
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("list", list);
		map.put("pagination", new Pagination(pageSize,pageNo,count));
		
		return map;
	}

	@Override
	public Map<String, Object> modifyParamInfo(Param param) {
		paramMapper.updateByPrimaryKey(param);
		return JSONUtil.getJSON(ErrorType.SUCCESS);
	}
	
	@Override
	public String getAboutUs() {
		String keyword = Key.about_us.getKey();
		Param param = paramMapper.selectByPrimaryKey(paramMapper.selectByPrimaryKey(keyword).getKeyword());
		return param.getValue();
	}

}
